#pragma once
#include "esp_io.h"

// SWCLK/TCK I/O DEDIC_PIN -------------------------------------

/** SWCLK/TCK I/O DEDIC_PIN: Get Input.
\return Current status of the SWCLK/TCK DAP hardware I/O DEDIC_PIN.
*/
__STATIC_FORCEINLINE uint32_t DEDIC_PIN_SWCLK_TCK_IN(void)
{
    return (0U);
}

/** SWCLK/TCK I/O DEDIC_PIN: Set Output to High.
  Set the SWCLK/TCK DAP hardware I/O DEDIC_PIN to high level.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWCLK_TCK_SET(void)
{
    esp_gpio_swclk_set();
}
//#include "esp_log.h"
/** SWCLK/TCK I/O DEDIC_PIN: Set Output to Low.
  Set the SWCLK/TCK DAP hardware I/O DEDIC_PIN to low level.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWCLK_TCK_CLR(void)
{
    //ESP_LOGI("Mdlink","SWCLK/TCK DAP hardware I/O DEDIC_PIN set to low level");
    esp_gpio_swclk_clr();
}

// SWDIO/TMS DEDIC_PIN I/O --------------------------------------

/** SWDIO/TMS I/O DEDIC_PIN: Get Input.
  \return Current status of the SWDIO/TMS DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE uint32_t DEDIC_PIN_SWDIO_TMS_IN(void)
{
    return esp_gpio_swdio_read();
}

/** SWDIO/TMS I/O DEDIC_PIN: Set Output to High.
  Set the SWDIO/TMS DAP hardware I/O DEDIC_PIN to high level.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWDIO_TMS_SET(void)
{
    esp_gpio_swdio_set();
}

/** SWDIO/TMS I/O DEDIC_PIN: Set Output to Low.
  Set the SWDIO/TMS DAP hardware I/O DEDIC_PIN to low level.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWDIO_TMS_CLR(void)
{
    esp_gpio_swdio_clr();
}

/** SWDIO I/O DEDIC_PIN: Get Input (used in SWD mode only).
  \return Current status of the SWDIO DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE uint32_t DEDIC_PIN_SWDIO_IN(void)
{
    return esp_gpio_swdio_read();
}

/** SWDIO I/O DEDIC_PIN: Set Output (used in SWD mode only).
  \param bit Output value for the SWDIO DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWDIO_OUT(uint32_t bit)
{
    esp_gpio_swdio_write(bit);
}

/** SWDIO I/O DEDIC_PIN: Switch to Output mode (used in SWD mode only).
  Configure the SWDIO DAP hardware I/O DEDIC_PIN to output mode. This function is
  called prior \ref DEDIC_PIN_SWDIO_OUT function calls.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWDIO_OUT_ENABLE(void)
{
    esp_gpio_swdio_out_enable();
}

/** SWDIO I/O DEDIC_PIN: Switch to Input mode (used in SWD mode only).
  Configure the SWDIO DAP hardware I/O DEDIC_PIN to input mode. This function is
  called prior \ref DEDIC_PIN_SWDIO_IN function calls.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_SWDIO_OUT_DISABLE(void)
{
    esp_gpio_swdio_out_disable();
}

// TDI DEDIC_PIN I/O ---------------------------------------------

/** TDI I/O DEDIC_PIN: Get Input.
  \return Current status of the TDI DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE uint32_t DEDIC_PIN_TDI_IN(void)
{
    return (0U);
}

/** TDI I/O DEDIC_PIN: Set Output.
  \param bit Output value for the TDI DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE void DEDIC_PIN_TDI_OUT(uint32_t bit)
{
    esp_gpio_tdi_write(bit);
}

// TDO DEDIC_PIN I/O ---------------------------------------------

/** TDO I/O DEDIC_PIN: Get Input.
  \return Current status of the TDO DAP hardware I/O DEDIC_PIN.
  */
__STATIC_FORCEINLINE uint32_t DEDIC_PIN_TDO_IN(void)
{
    return esp_gpio_tdo_read();
}

__STATIC_FORCEINLINE void DEDIC_PIN_TCK_SET(void);
__STATIC_FORCEINLINE void DEDIC_PIN_TCK_CLR(void);
__STATIC_FORCEINLINE void DEDIC_PIN_TMS_SET(void);
__STATIC_FORCEINLINE void DEDIC_PIN_TMS_CLR(void);

/** 设置 TCK 为高电平 */
__STATIC_FORCEINLINE void DEDIC_PIN_TCK_SET(void)
{
    esp_gpio_tck_set();
}

/** 设置 TCK 为低电平 */
__STATIC_FORCEINLINE void DEDIC_PIN_TCK_CLR(void)
{
    esp_gpio_tck_clr();
}

//-----------------------------
// TMS 控制
//-----------------------------

/** 设置 TMS 为高电平 */
__STATIC_FORCEINLINE void DEDIC_PIN_TMS_SET(void){
    esp_gpio_tms_set();
}

/** 设置 TMS 为低电平 */
__STATIC_FORCEINLINE void DEDIC_PIN_TMS_CLR(void)
{
    esp_gpio_tms_clr();
}